﻿#pragma warning(disable: 4996)
#pragma warning(disable: 6031)

/*
7-49 Have Fun with Numbers (20 分)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!

Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

Input Specification:
Each input contains one test case. Each case contains one positive integer with no more than 20 digits.

Output Specification:
For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.

Sample Input:
1234567899
Sample Output:
Yes
2469135798
*/

#include <stdio.h>
#include <math.h>
#define MAX_BITS 30

int n=0;
int origin[MAX_BITS] = { 0 };
int calc[MAX_BITS] = { 0 };
int doubledNum[MAX_BITS] = { 0 };
int count[10] = { 0 };
int count2[10] = {0};


void solve2()
{
	for (int i = n; i > 0; --i)
	{
		int d = origin[i] * 2 + calc[i];
		calc[i] = d % 10;
		calc[i - 1] = d / 10;
		count2[calc[i]]++;
	}
	int is_equal = 1;
	for (int i = 0; i < 10; ++i) {
		if (count[i] != count2[i]) {
			is_equal = 0;
			break;
		}
	}
	if (is_equal)
	{
		printf("Yes\n");
		if (calc[0])
			printf("%d", calc[0]);
		for (int i = 1; i <= n; ++i)
			printf("%d", calc[i]);
		printf("\n");
	}
	else
		printf("No\n");
}

void solve()
{
	for (int i = 1; i <= n; ++i)
	{
		doubledNum[i] = origin[i] * 2;
	}
	for (int i = n; i > 0; --i)
	{
		doubledNum[i - 1] += doubledNum[i] / 10;
		doubledNum[i] %= 10;
		count2[doubledNum[i]]++;
	}

	int is_equal = doubledNum[0] == 0;
	if (is_equal) {
		for (int i = 0; i < 10; ++i) {
			if (count[i] != count2[i]) {
				is_equal = 0;
				break;
			}
		}
	}
	if (is_equal)
		printf("Yes\n");
	else
		printf("No\n");
	if (doubledNum[0])
		printf("%d", doubledNum[0]);
	for (int i = 1; i <= n; ++i)
		printf("%d", doubledNum[i]);
	printf("\n");
}

void read_data() 
{
	char a = 0;
	n = 0;
	a = getchar();
	while (a >= '0' && a <= '9')
	{
		int i = a - '0';
		origin[++n] = i;
		count[i]++;
		a = getchar();
	}
}

int main()
{
	freopen("D:/Develop/GitRepos/MOOC/浙江大学/数据结构/201906/DataStructure/M2019秋C入门和进阶练习集/7-49.txt", "r", stdin);
	read_data();
	solve();
	return 0;
}

